package cn.scantd.core.model;

import java.util.ArrayList;
import java.util.List;

import org.eclipse.jdt.core.dom.Javadoc;
import org.eclipse.jdt.core.dom.TagElement;
import org.eclipse.jdt.core.dom.TextElement;

import cn.scantd.core.attrs.Level;
import cn.scantd.kit.StrKit;

public class JavaDoc {

    private Level level;
    private String text;
    private List<JavaDocTag> tags = new ArrayList<>();
    
    @SuppressWarnings("unchecked")
    public JavaDoc(Javadoc javadoc) {
        if (javadoc == null) {
            return;
        }
        for (Object obj : javadoc.tags()) {
            TagElement tag = (TagElement) obj;
            List<TextElement> fragments = tag.fragments();
            if (fragments == null || fragments.size()  == 0) {
                continue;
            }
            if (tag.getTagName() == null) {
                text = StrKit.trim(fragments.get(0).getText());
            } else {
                JavaDocTag javaDocTag = new JavaDocTag(tag);
                tags.add(javaDocTag);
            }
        }
    }
    
    public Level getLevel() {
        return level;
    }
    public void setLevel(Level level) {
        this.level = level;
    }
    public String getText() {
        return text;
    }
    public void setText(String text) {
        this.text = text;
    }
    public List<JavaDocTag> getTags() {
        return tags;
    }
    public void setTags(List<JavaDocTag> tags) {
        this.tags = tags;
    }
    
}
